package org.example.rocketmqstudy.producer;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.util.ArrayList;
import java.util.List;

public class BatchProducer {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("BatchProducerGroupName");
        producer.setNamesrvAddr("8.138.36.56:9876");
        producer.start();

        //If you just send messages of no more than 1MiB at a time, it is easy to use batch
        //Messages of the same batch should have: same topic, same waitStoreMsgOK and no schedule support
        String topic = "test-batch-send";
        List<Message> messages = new ArrayList<>();
        for (int i = 0 ; i < 10 ; i++) {
            messages.add(new Message(topic, "Tag", ("Hello world " + i).getBytes()));
        }
        producer.send(messages);
    }
}
